package com.ccp.dev.qbdms.service;

import com.ccp.dev.core.basic.web.query.QueryFilter;
import com.ccp.dev.form.service.impl.ScriptImpl;
import com.ccp.dev.qbdms.consts.ZhiLiangConst;
import com.ccp.dev.qbdms.model.WQbdReportTemplate;
import com.ccp.dev.qbdms.model.vo.ModelQualityStatisticsParamVo;
import java.text.ParseException;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.annotation.Resource;

import com.ccp.dev.qbdms.util.BaseUtil;
import org.apache.commons.lang3.time.DateUtils;
import org.springframework.stereotype.Service;

/**
 * ClassDescribe:
 *
 * @author :milihao
 */
@Service
public class ModelQualityStatisticsService {

	@Resource
	private WQbdReportTemplateService wQbdReportTemplateService;
	@Resource
	public ScriptImpl scriptimpl;

	public List<Map<String, Object>> getChartData(
			ModelQualityStatisticsParamVo modelQualityStatisticsParamVo, QueryFilter queryFilter) {
		ZhiLiangConst.addQueryFilter(queryFilter);
		List<Map<String, Object>> list = new ArrayList<>();
		// 添加密级过滤
		Map<String, Object> querymap = new HashMap<>();
//		querymap.put("reportStatus", queryFilter.get("reportStatus"));
		querymap.put("secret", scriptimpl.getCurrentUser().getPrivacyLevel());
		querymap.put("modelSymbol", modelQualityStatisticsParamVo.getModelSymbol());
		querymap.put("dutyDeptRoom", modelQualityStatisticsParamVo.getDutyDept());
		querymap.put("belongdeptname", BaseUtil.getCurrentTenOrgCodePath() + "%");
		WQbdReportTemplate wQbdReportTemplate = new WQbdReportTemplate();
		Date startTime = new Date();
		Date endTime = new Date();
		try {
			startTime = DateUtils.parseDate(modelQualityStatisticsParamVo.getBeginTime(), "yyyy-MM-dd");
			endTime = DateUtils.parseDate(modelQualityStatisticsParamVo.getEndTime(), "yyyy-MM-dd");
		} catch (ParseException e) {
				e.printStackTrace();
		}
		wQbdReportTemplate.setQualityProblemStart(startTime);
		wQbdReportTemplate.setQualityProblemEnd(endTime);
		wQbdReportTemplate.setQualityProblem("andtj");
		if (("三年柱形图").equals(modelQualityStatisticsParamVo.getStatisticalMethods())) {
			//质量问题统计
			list.add(wQbdReportTemplateService
					.getQualityProblemData(wQbdReportTemplateService.CHART_BAR, wQbdReportTemplate,
							querymap));
			list.add(wQbdReportTemplateService
					.getQualityProblemData(wQbdReportTemplateService.TABLE, wQbdReportTemplate, querymap));
		} else if (("研制型号按原因统计").equals(modelQualityStatisticsParamVo.getStatisticalMethods())) {
			//研制型号按原因统计
			list.add(wQbdReportTemplateService
					.getProblemChartDateByWorkPhase(wQbdReportTemplateService.CHART_BAR, wQbdReportTemplate,
							wQbdReportTemplateService.DEVELOPMENT, querymap));
			list.add(wQbdReportTemplateService
					.getProblemChartDateByWorkPhase(wQbdReportTemplateService.CHART_PIE, wQbdReportTemplate,
							wQbdReportTemplateService.DEVELOPMENT, querymap));

		} else if (("批产型号按原因统计").equals(modelQualityStatisticsParamVo.getStatisticalMethods())) {
			//批产型号按原因统计
			list.add(wQbdReportTemplateService
					.getProblemChartDateByWorkPhase(wQbdReportTemplateService.CHART_BAR, wQbdReportTemplate,
							wQbdReportTemplateService.MASS_PRODUCTION, querymap));
			list.add(wQbdReportTemplateService
					.getProblemChartDateByWorkPhase(wQbdReportTemplateService.CHART_PIE, wQbdReportTemplate,
							wQbdReportTemplateService.MASS_PRODUCTION, querymap));
		}
		else if(("研制型号按阶段统计").equals(modelQualityStatisticsParamVo.getStatisticalMethods())){
			list.add(wQbdReportTemplateService.getModelDevChartDateByWorkPhase(wQbdReportTemplateService.CHART_BAR, wQbdReportTemplate, querymap));
			list.add(wQbdReportTemplateService.getModelDevChartDateByWorkPhase(wQbdReportTemplateService.CHART_PIE, wQbdReportTemplate, querymap));
		} else if(("批产型号按阶段统计").equals(modelQualityStatisticsParamVo.getStatisticalMethods())){
			list.add(wQbdReportTemplateService.getProduceChartDataByWorkPhase(wQbdReportTemplateService.CHART_BAR, wQbdReportTemplate, querymap));
			list.add(wQbdReportTemplateService.getProduceChartDataByWorkPhase(wQbdReportTemplateService.CHART_PIE, wQbdReportTemplate, querymap));
		} else if(("质量问题按月份统计").equals(modelQualityStatisticsParamVo.getStatisticalMethods())){
			wQbdReportTemplate.setQualityProblem("aydtj");
			list.add(wQbdReportTemplateService
					.getProblemChartDateByMonth(wQbdReportTemplateService.CHART_BAR, wQbdReportTemplate, querymap));
			list.add(wQbdReportTemplateService
					.getProblemChartDateByMonth(wQbdReportTemplateService.CHART_PIE, wQbdReportTemplate, querymap));
		} else if(("质量问题按研究室分布").equals(modelQualityStatisticsParamVo.getStatisticalMethods())) {
			list.add(wQbdReportTemplateService
					.getProblemChartDateByDutyRoom(wQbdReportTemplateService.CHART_BAR, wQbdReportTemplate, querymap));
			list.add(wQbdReportTemplateService
					.getProblemChartDateByDutyRoom(wQbdReportTemplateService.CHART_PIE, wQbdReportTemplate, querymap));
		}
			return list;
	}
}
